home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / g++ / CursesW.h < prev    next >
C/C++ Source or Header  |  1995-02-06  |  14KB  |  579 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1989 Free Software Foundation
  5.     written by Eric Newton (newton@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #ifndef _CursesWindow_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #pragma cplusplus
  24. #endif
  25. #define _CursesWindow_h
  26.  
  27. #include   <_G_config.h>
  28. #if _G_HAVE_CURSES
  29. extern "C" {
  30. #include   <curses.h>
  31. }
  32. /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
  33.    Undefine it here, because CursesWindow uses lines as a method.  */
  34. #undef lines
  35.  
  36. // "Convert" macros to inlines, if needed.
  37. #ifdef addch
  38. inline int (addch)(char ch)  { return addch(ch); }
  39. #undef addch
  40. #endif
  41. #ifdef addstr
  42. /* The (char*) cast is to hack around missing const's */
  43. inline int (addstr)(const char * str)  { return addstr((char*)str); }
  44. #undef addstr
  45. #endif
  46. #ifdef clear
  47. inline int (clear)()  { return clear(); }
  48. #undef clear
  49. #endif
  50. #ifdef clearok
  51. inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
  52. #undef clearok
  53. #else
  54. extern "C" int clearok(WINDOW*, int);
  55. #endif
  56. #ifdef clrtobot
  57. inline int (clrtobot)()  { return clrtobot(); }
  58. #undef clrtobot
  59. #endif
  60. #ifdef clrtoeol
  61. inline int (clrtoeol)()  { return clrtoeol(); }
  62. #undef clrtoeol
  63. #endif
  64. #ifdef delch
  65. inline int (delch)()  { return delch(); }
  66. #undef delch
  67. #endif
  68. #ifdef deleteln
  69. inline int (deleteln)()  { return deleteln(); }
  70. #undef deleteln
  71. #endif
  72. #ifdef erase
  73. inline int (erase)()  { return erase(); }
  74. #undef erase
  75. #endif
  76. #ifdef flushok
  77. inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
  78. #undef flushok
  79. #else
  80. #define _no_flushok
  81. #endif
  82. #ifdef getch
  83. inline int (getch)()  { return getch(); }
  84. #undef getch
  85. #endif
  86. #ifdef getstr
  87. inline int (getstr)(char *_str)  { return getstr(_str); }
  88. #undef getstr
  89. #endif
  90. #ifdef getyx
  91. inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
  92. #undef getyx
  93. #endif
  94. #ifdef inch
  95. inline int (inch)()  { return inch(); }
  96. #undef inch
  97. #endif
  98. #ifdef insch
  99. inline int (insch)(char c)  { return insch(c); }
  100. #undef insch
  101. #endif
  102. #ifdef insertln
  103. inline int (insertln)()  { return insertln(); }
  104. #undef insertln
  105. #endif
  106. #ifdef leaveok
  107. inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
  108. #undef leaveok
  109. #else
  110. extern "C" int leaveok(WINDOW* win, int bf);
  111. #endif
  112. #ifdef move
  113. inline int (move)(int x, int y)  { return move(x, y); }
  114. #undef move
  115. #endif
  116. #ifdef refresh
  117. inline int (rfresh)()  { return refresh(); }
  118. #undef refresh
  119. #endif
  120. #ifdef scrollok
  121. inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
  122. #undef scrollok
  123. #else
  124. #ifndef hpux
  125. extern "C" int scrollok(WINDOW*, int);
  126. #else
  127. extern "C" int scrollok(WINDOW*, char);
  128. #endif
  129. #endif
  130. #ifdef standend
  131. inline int (standend)()  { return standend(); }
  132. #undef standend
  133. #endif
  134. #ifdef standout
  135. inline int (standout)()  { return standout(); }
  136. #undef standout
  137. #endif
  138. #ifdef wstandend
  139. inline int (wstandend)(WINDOW *win)  { return wstandend(win); }
  140. #undef wstandend
  141. #endif
  142. #ifdef wstandout
  143. inline int (wstandout)(WINDOW *win)  { return wstandout(win); }
  144. #undef wstandout
  145. #endif
  146. #ifdef winch
  147. inline int (winch)(WINDOW* win) { return winch(win); }
  148. #undef winch
  149. #endif
  150.  
  151. #ifdef mvwaddch
  152. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  153. { return mvwaddch(win, y, x, ch); }
  154. #undef mvwaddch
  155. #endif
  156. #ifdef mvwaddstr
  157. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  158. { return mvwaddstr(win, y, x, (char*)str); }
  159. #undef mvwaddstr
  160. #endif
  161. #ifdef mvwdelch
  162. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  163. #undef mvwdelch
  164. #endif
  165. #ifdef mvwgetch
  166. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  167. #undef mvwgetch
  168. #endif
  169. #ifdef mvwgetstr
  170. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  171. {return mvwgetstr(win,y,x, str);}
  172. #undef mvwgetstr
  173. #endif
  174. #ifdef mvwinch
  175. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  176. #undef mvwinch
  177. #endif
  178. #ifdef mvwinsch
  179. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  180. { return mvwinsch(win, y, x, c); }
  181. #undef mvwinsch
  182. #endif
  183.  
  184. #ifdef mvaddch
  185. inline int (mvaddch)(int y, int x, char ch)
  186. { return mvaddch(y, x, ch); }
  187. #undef mvaddch
  188. #endif
  189. #ifdef mvaddstr
  190. inline int (mvaddstr)(int y, int x, const char * str)
  191. { return mvaddstr(y, x, (char*)str); }
  192. #undef mvaddstr
  193. #endif
  194. #ifdef mvdelch
  195. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  196. #undef mvdelch
  197. #endif
  198. #ifdef mvgetch
  199. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  200. #undef mvgetch
  201. #endif
  202. #ifdef mvgetstr
  203. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  204. #undef mvgetstr
  205. #endif
  206. #ifdef mvinch
  207. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  208. #undef mvinch
  209. #endif
  210. #ifdef mvinsch
  211. inline int (mvinsch)(int y, int x, char c)
  212. { return mvinsch(y, x, c); }
  213. #undef mvinsch
  214. #endif
  215.  
  216. /*
  217.  *
  218.  * C++ class for windows.
  219.  *
  220.  *
  221.  */
  222.  
  223. class CursesWindow 
  224. {
  225. protected:
  226.   static int     count;           // count of all active windows:
  227.                                   //   We rely on the c++ promise that
  228.                                   //   all otherwise uninitialized
  229.                                   //   static class vars are set to 0
  230.  
  231.   WINDOW *       w;               // the curses WINDOW
  232.  
  233.   int            alloced;         // true if we own the WINDOW
  234.  
  235.   CursesWindow*  par;             // parent, if subwindow
  236.   CursesWindow*  subwins;         // head of subwindows list
  237.   CursesWindow*  sib;             // next subwindow of parent
  238.  
  239.   void           kill_subwindows(); // disable all subwindows
  240.  
  241. public:
  242.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  243.  
  244.                  CursesWindow(int lines,          // number of lines
  245.                               int cols,           // number of columns
  246.                               int begin_y,        // line origin
  247.                               int begin_x);       // col origin
  248.  
  249.                  CursesWindow(CursesWindow& par,  // parent window
  250.                               int lines,          // number of lines
  251.                               int cols,           // number of columns
  252.                               int by,             // absolute or relative
  253.                               int bx,             //   origins:
  254.                               char absrel = 'a'); // if `a', by & bx are
  255.                                                   // absolute screen pos,
  256.                                                   // else if `r', they are
  257.                                                   // relative to par origin
  258.                 ~CursesWindow();
  259.  
  260. // terminal status
  261.   int            lines(); // number of lines on terminal, *not* window
  262.   int            cols();  // number of cols  on terminal, *not* window
  263.  
  264. // window status
  265.   int            height(); // number of lines in this window
  266.   int            width();  // number of cols in this window
  267.   int            begx();   // smallest x coord in window
  268.   int            begy();   // smallest y coord in window
  269.   int            maxx();   // largest  x coord in window
  270.   int            maxy();   // largest  x coord in window
  271.  
  272. // window positioning
  273.   int            move(int y, int x);
  274.  
  275. // coordinate positioning
  276.   void           getyx(int& y, int& x);
  277.   int            mvcur(int sy, int ey, int sx, int ex);
  278.  
  279. // input
  280.   int            getch();
  281.   int            getstr(char * str);
  282.   int            scanw(const char *, ...);
  283.  
  284. // input + positioning
  285.   int            mvgetch(int y, int x);
  286.   int            mvgetstr(int y, int x, char * str);
  287.   int            mvscanw(int, int, const char*, ...);
  288.  
  289. // output
  290.   int            addch(const char ch);
  291.   int            addstr(const char * str);
  292.   int            printw(const char * fmt, ...);
  293.   int            inch();
  294.   int            insch(char c);
  295.   int            insertln();
  296.  
  297. // output + positioning
  298.   int            mvaddch(int y, int x, char ch);
  299.   int            mvaddstr(int y, int x, const char * str);
  300.   int            mvprintw(int y, int x, const char * fmt, ...);
  301.   int            mvinch(int y, int x);
  302.   int            mvinsch(int y, int x, char ch);
  303.  
  304. // borders
  305.   int            box(char vert, char  hor);
  306.  
  307. // erasure
  308.   int            erase();
  309.   int            clear();
  310.   int            clearok(int bf);
  311.   int            clrtobot();
  312.   int            clrtoeol();
  313.   int            delch();
  314.   int            mvdelch(int y, int x);
  315.   int            deleteln();
  316.  
  317. // screen control
  318.   int            scroll();
  319.   int            scrollok(int bf);
  320.   int            touchwin();
  321.   int            refresh();
  322.   int            leaveok(int bf);
  323. #ifndef _no_flushok
  324.   int            flushok(int bf);
  325. #endif
  326.   int            standout();
  327.   int            standend();
  328.  
  329. // multiple window control
  330.   int            overlay(CursesWindow &win);
  331.   int            overwrite(CursesWindow &win);
  332.  
  333.  
  334. // traversal support
  335.   CursesWindow*  child();
  336.   CursesWindow*  sibling();
  337.   CursesWindow*  parent();
  338. };
  339.  
  340.  
  341. inline int CursesWindow::begx()
  342. {
  343.   return w->_begx;
  344. }
  345.  
  346. inline int CursesWindow::begy()
  347. {
  348.   return w->_begy;
  349. }
  350.  
  351. inline int CursesWindow::maxx()
  352. {
  353.   return w->_maxx;
  354. }
  355.  
  356. inline int CursesWindow::maxy()
  357. {
  358.   return w->_maxy;
  359. }
  360.  
  361. inline int CursesWindow::height()
  362. {
  363.   return maxy() - begy() + 1;
  364. }
  365.  
  366. inline int CursesWindow::width()
  367. {
  368.   return maxx() - begx() + 1;
  369. }
  370.  
  371. inline int CursesWindow::box(char vert, char  hor)    
  372. {
  373.   return ::box(w, vert, hor); 
  374. }
  375.  
  376. inline int CursesWindow::overlay(CursesWindow &win)         
  377. {
  378.   return ::overlay(w, win.w); 
  379. }
  380.  
  381. inline int CursesWindow::overwrite(CursesWindow &win)       
  382. {
  383.   return ::overwrite(w, win.w); 
  384. }
  385.  
  386. inline int CursesWindow::scroll()                     
  387. {
  388.   return ::scroll(w); 
  389. }
  390.  
  391.  
  392. inline int CursesWindow::touchwin()                   
  393. {
  394.   return ::touchwin(w); 
  395. }
  396.  
  397. inline int CursesWindow::addch(const char ch)         
  398. {
  399.   return ::waddch(w, ch); 
  400. }
  401.  
  402. inline int CursesWindow::addstr(const char * str)     
  403. {
  404.   // The (char*) cast is to hack around prototypes in curses.h that
  405.   // have const missing in the parameter lists.  [E.g. SVR4]
  406.   return ::waddstr(w, (char*)str); 
  407. }
  408.  
  409. inline int CursesWindow::clear()                      
  410. {
  411.   return ::wclear(w); 
  412. }
  413.  
  414. inline int CursesWindow::clrtobot()                   
  415. {
  416.   return ::wclrtobot(w); 
  417. }
  418.  
  419. inline int CursesWindow::clrtoeol()                   
  420. {
  421.   return ::wclrtoeol(w); 
  422. }
  423.  
  424. inline int CursesWindow::delch()                      
  425. {
  426.   return ::wdelch(w); 
  427. }
  428.  
  429. inline int CursesWindow::deleteln()                   
  430. {
  431.   return ::wdeleteln(w); 
  432. }
  433.  
  434. inline int CursesWindow::erase()                      
  435. {
  436.   return ::werase(w); 
  437. }
  438.  
  439. inline int CursesWindow::getch()                      
  440. {
  441.   return ::wgetch(w); 
  442. }
  443.  
  444. inline int CursesWindow::getstr(char * str)           
  445. {
  446.   return ::wgetstr(w, str); 
  447. }
  448.  
  449. inline int CursesWindow::inch()                       
  450. {
  451.   return winch(w); 
  452. }
  453.  
  454. inline int CursesWindow::insch(char c)               
  455. {
  456.   return ::winsch(w, c); 
  457. }
  458.  
  459. inline int CursesWindow::insertln()                   
  460. {
  461.   return ::winsertln(w); 
  462. }
  463.  
  464. inline int CursesWindow::move(int y, int x)           
  465. {
  466.   return ::wmove(w, y, x); 
  467. }
  468.  
  469.  
  470. inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
  471. {
  472.   return ::mvcur(sy, ey, sx,ex);
  473. }
  474.  
  475. inline int CursesWindow::mvaddch(int y, int x, char ch)
  476. {
  477.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
  478. }
  479.  
  480. inline int CursesWindow::mvgetch(int y, int x)
  481. {
  482.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
  483. }
  484.  
  485. inline int CursesWindow::mvaddstr(int y, int x, const char * str)
  486. {
  487.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
  488. }
  489.  
  490. inline int CursesWindow::mvgetstr(int y, int x, char * str)
  491. {
  492.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
  493. }
  494.  
  495. inline int CursesWindow::mvinch(int y, int x)
  496. {
  497.   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
  498. }
  499.  
  500. inline int CursesWindow::mvdelch(int y, int x)
  501. {
  502.   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
  503. }
  504.  
  505. inline int CursesWindow::mvinsch(int y, int x, char ch)
  506. {
  507.   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
  508. }
  509.  
  510. inline int CursesWindow::refresh()                   
  511. {
  512.   return ::wrefresh(w); 
  513. }
  514.  
  515. inline int CursesWindow::clearok(int bf)             
  516. {
  517.   return ::clearok(w,bf); 
  518. }
  519.  
  520. inline int CursesWindow::leaveok(int bf)             
  521. {
  522.   return ::leaveok(w,bf); 
  523. }
  524.  
  525. inline int CursesWindow::scrollok(int bf)            
  526. {
  527.   return ::scrollok(w,bf); 
  528. }
  529.  
  530. #ifndef _no_flushok
  531. inline int CursesWindow::flushok(int bf)            
  532. {
  533.   return ::flushok(w, bf); 
  534. }
  535. #endif
  536.  
  537. inline void CursesWindow::getyx(int& y, int& x)       
  538. {
  539.   ::getyx(w, y, x); 
  540. }
  541.  
  542. inline int CursesWindow::standout()                   
  543. {
  544.   return ::wstandout(w); 
  545. }
  546.  
  547. inline int CursesWindow::standend()                   
  548. {
  549.   return ::wstandend(w); 
  550. }
  551.  
  552. inline int CursesWindow::lines()                      
  553. {
  554.   return LINES; 
  555. }
  556.  
  557. inline int CursesWindow::cols()                       
  558. {
  559.   return COLS; 
  560. }
  561.  
  562. inline CursesWindow* CursesWindow::child()
  563. {
  564.   return subwins;
  565. }
  566.  
  567. inline CursesWindow* CursesWindow::parent()
  568. {
  569.   return par;
  570. }
  571.  
  572. inline CursesWindow* CursesWindow::sibling()
  573. {
  574.   return sib;
  575. }
  576.  
  577. #endif /* _G_HAVE_CURSES */
  578. #endif
  579.